#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 50
/*Структура*/
struct Inform
{
    char* phone;
    char* name;
    int exist;
};
struct Inform table_for_num[N] = {};

int main()
{
    int m;
    for (m = 0;m < N; m++)
    {
        table_for_num[m].exist = 0;
        table_for_num[m].name = (char*) calloc(15, (sizeof(char)));
        table_for_num[m].phone = (char*) calloc(11,(sizeof(char)));
    }

    char signal_word[7];
    char name_of_p[40];
    char mob_phone[10];

    char* result_1 = (char*)calloc(11, sizeof(char));
    int result;
/*Проверка ввода*/
    while((scanf ("%s", signal_word))!= EOF)
{
        if(strcmp(signal_word, "INSERT") == 0)
        {
            scanf("%s %s", name_of_p, mob_phone);
        }

        char* name_p  = (char*)calloc(strlen(name_of_p), sizeof(char));
        strcpy(name_p, name_of_p);

        char* phone_p = (char*)calloc(strlen(mob_phone), sizeof(char));
        strcpy(phone_p, mob_phone);


         if(strcmp(signal_word, "INSERT") == 0)
            {
                result=paste_into_table(name_p, phone_p);
                printf("\n");
            }
     
                else
                    printf("\n");
}
  return 0;
}

/*Вставка в таблицу*/
int paste_into_table (char* name_p, char* phone_p)
{
    /*Хеш функция*/
  int chislo = 0;
  int k;
  for(k = 0; k < strlen(name_p); k++)
    chislo = chislo+name_p[k]-'A';

  unsigned int key = chislo % N;
  unsigned int i = key;


  while ( i < N + key )
  {
        if ((table_for_num[i%N].exist == 1) && (strcmp(table_for_num[i%N].name, name_p) == 0))
        {
            char* znach = (char*)calloc(11, sizeof(char));
            strcpy(znach, table_for_num[i%N].phone);
            strcpy(table_for_num[i%N].phone, phone_p);
            printf("Changed. Old value = %s\n",znach);
/*Замена значения номера*/
            return 1;
        }
        else
            if((table_for_num[i%N].exist == 1) && (strcmp(table_for_num[i%N].name, name_p)!= 0))
               i++;
        else
            if(table_for_num[i%N].exist == 0)
                break;
  }
/*Вставка нового человека и номера*/
  if ( i != (key+N) )
     {
       strcpy(table_for_num[i].name, name_p) ;
       strcpy(table_for_num[i].phone, phone_p);
       table_for_num[i].exist = 1;
       printf("OK\n");
       return 1;
     }

}
       printf("OK\n");
       return 1;
     }

}


